package cn.hncev.xiaohui;

import java.util.HashSet;
public class ExampleTest35 {
		public static void main(String[] args) {
			HashSet hsHashSet = new HashSet();
			Stu s1=new Stu("1","肖小");
			Stu s2=new Stu("2","小小");
			Stu s3=new Stu("2","哈哈");
			hsHashSet.add(s1);
			hsHashSet.add(s2);
			hsHashSet.add(s3);
			System.out.println(hsHashSet);
	}
	}
	class Stu{
		String id;
		String name;
		public Stu (String id,String name) {
			this.id=id;
			this.name=name;
		}
		//重写toString方法
		public String toString() {
			return id + ":" + name;
		}	
		
		//重写hashCode方法
		public int hashCode() {
			return id.hashCode();
		}
		//重写equals方法
		public boolean equals(Object object) {
			if(this == object) {	//判断当前是否是同一个对象
				return true;
			}
		if(!(object instanceof Stu)) {
			return false;
		}
		Stu stu =(Stu) object;
		boolean b = this.id.equals(stu.id);
		return b;
	}
}



